

<template>
<div>
     <!-- <Button type="primary" @click="modal1 = true">Display dialog box</Button> -->
     <Modal v-model="mode" width="60%"  title="红枣质押-结算" @change="testChange"  @on-cancel="cancel">
         <Form ref="EntryOrderData"  :model="EntryOrderData"  :rules="ruleInUser" :label-width="100" style="margin-left:20px;">
          <Row>
            <FormItem label="订单编号：" prop="Id">
              <Input v-model="EntryOrderData.OrderNo" class="orders_disabled" placeholder="请输入用户编号" disabled />
            </FormItem>
            <FormItem label="客户名称：" prop="ClassName">
              <label slot="label">客户名称：</label>
            <Input v-model="EntryOrderData.CustomerName" class="orders_disabled_custom" placeholder="请输入客户名称"  disabled/>
            </FormItem> 
          </Row>
          <br>
          <Row>
              <i-col span="8">
                <FormItem label="毛重时间：" prop="RoughWeightTime">
                  <Input v-model="EntryOrderData.RoughWeightTime"  class="orders_disabled" placeholder="请输入申请时间" style="width:200px;" disabled/>
                </FormItem> 

                <FormItem label="毛重(公斤)：" prop="RoughWeight">
                  <InputNumber v-model="EntryOrderData.RoughWeight" class="orders_disabled" placeholder="请输入质押件数" style="width:100px;"  disabled/>
                </FormItem> 
                <FormItem label="红枣品级1：" prop="CheckTypeFst" v-if="EntryOrderData.CheckTypeFst != ''">
                  <Input v-model="EntryOrderData.CheckTypeFst"  class="orders_disabled" placeholder="请输入红枣品级" style="width:100px;" disabled/>
                </FormItem>  

                <FormItem label="红枣品级2：" prop="CheckTypeFst" v-if="EntryOrderData.CheckTypeSec != ''">
                  <Input v-model="EntryOrderData.CheckTypeSec"  class="orders_disabled" placeholder="无" style="width:100px;" disabled/>
                </FormItem>
                 
                <FormItem label="红枣品级3：" prop="CheckTypeFst" v-if="EntryOrderData.CheckTypeThd != ''">
                  <Input v-model="EntryOrderData.CheckTypeThd"  class="orders_disabled" placeholder="无" style="width:100px;" disabled/>
                </FormItem> 

                <FormItem label="每件重量：" prop="UnitWeight">
                    <InputNumber v-model="EntryOrderData.UnitWeight" class="orders_disabled" placeholder="请输入质押件数" style="width:100px;"  disabled/>
                </FormItem> 

                <FormItem label="占比率%：" prop="Scale">
                    <InputNumber v-model="EntryOrderData.Scale" @on-change="scaleChange" class="orders_disabled" placeholder="请输入质押件数" style="width:100px;" />
                </FormItem> 
              </i-col>


              <i-col span="8">
                <FormItem label="皮重时间：" prop="SkinWeightTime">
                    <Input v-model="EntryOrderData.SkinWeightTime" class="orders_disabled" placeholder="请输入联系电话" style="width:200px;" disabled/>
                </FormItem> 

                <FormItem label="皮重(公斤)：" prop="SkinWeight">
                    <InputNumber v-model="EntryOrderData.SkinWeight" class="orders_disabled" placeholder="请输入质押件数" style="width:100px;"  disabled/>
                </FormItem> 

                <FormItem label="质押件数：" prop="CheckFstCount" v-if="EntryOrderData.CheckTypeFst != ''">
                    <InputNumber v-model="EntryOrderData.CheckFstCount" class="orders_disabled" placeholder="请输入质押件数" style="width:100px;" disabled/>
                </FormItem> 

                <FormItem label="质押件数：" prop="CheckSecCount" v-if="EntryOrderData.CheckTypeSec != ''">
                    <InputNumber v-model="EntryOrderData.CheckSecCount" class="orders_disabled" placeholder="请输入质押件数" style="width:100px;" disabled />
                </FormItem>

                <FormItem label="质押件数：" prop="CheckThdCount" v-if="EntryOrderData.CheckTypeThd != ''">
                    <InputNumber v-model="EntryOrderData.CheckThdCount" class="orders_disabled" placeholder="请输入质押件数" style="width:100px;" disabled />
                </FormItem>

                <FormItem label="结算重量：" prop="AccountWeight">
                    <InputNumber v-model="EntryOrderData.AccountWeight" class="orders_disabled" placeholder="请输入质押件数" style="width:100px;"  disabled/>
                </FormItem> 
                
                <FormItem label="实付金额：" prop="RealMoney">
                    <InputNumber v-model="EntryOrderData.RealMoney" class="orders_disabled" placeholder="请输入质押件数" style="width:100px;"  disabled/>
                </FormItem> 
              </i-col>

              <i-col span="8">
                <FormItem label="占空位：" prop="">
                  <label slot="label">&nbsp;&nbsp;&nbsp;&nbsp;</label>
                </FormItem> 

                <FormItem label="净重(公斤)：" prop="NetWeight">
                  <InputNumber v-model="EntryOrderData.NetWeight" class="orders_disabled" placeholder="请输入质押件数" style="width:100px;"  disabled/>
                </FormItem> 
              </i-col>


              <i-col span="8">
                <FormItem label="入库位置：" prop="LandingPlaceFst" v-if="EntryOrderData.CheckTypeFst != ''">
                  <Input v-model="EntryOrderData.LandingPlaceFst"  class="orders_disabled" placeholder="请输入场地" style="width:100px;" disabled/>
                </FormItem>  
                <FormItem label="入库位置：" prop="LandingPlaceSec" v-if="EntryOrderData.CheckTypeSec != ''">
                  <Input v-model="EntryOrderData.LandingPlaceSec"  class="orders_disabled" placeholder="请输入场地" style="width:100px;" disabled/>
                </FormItem> 
                <FormItem label="入库位置：" prop="LandingPlaceThd" v-if="EntryOrderData.CheckTypeThd != ''">
                  <Input v-model="EntryOrderData.LandingPlaceThd"  class="orders_disabled" placeholder="请输入场地" style="width:100px;" disabled/>
                </FormItem>  
                <FormItem label="结算金额：" prop="SumMoney">
                    <InputNumber v-model="EntryOrderData.SumMoney" class="orders_disabled" placeholder="请输入质押件数" style="width:100px;"  disabled/>
                </FormItem> 
              </i-col>
          </Row>
          <br>
          <Row>
              <i-col span="6">
                <FormItem>
                  <Button type="primary" :loading="loading" class="buttn_rough"  @click="handleSubmit('EntryOrderData',7)">结算</Button>
                  <!--
                  <Button type="warning" :loading="loading" class="buttn_skin" @click="handleSubmit('EntryOrderData')">称皮重</Button>
                  <Button @click="handleReset('formValidate')" style="margin-left: 8px">重置</Button>
                   -->
                </FormItem>
              </i-col>
          </Row>      
        </Form>

        <div slot="footer" >
            <!-- <Button type="error" size="large" long :loading="modal_loading" @click="del">Delete</Button> -->
        </div>
    </Modal>
</div>
</template>

<script>
import {getCompanyList,getDeptList,updateEntryOrderData,timestampToDate} from "@/api/data";
import { formatDate } from '../../components/date.js';
import { getToken } from "@/libs/util";
export default {
    name: 'Edit',
    data () {
        return {
          loading:false,
          mode:this.edit,
          
          //表单验证规则
          ruleInUser: {

          },
         
          listdata:[]

        };
    },
    props:{
        edit:{
            type:Boolean ,
            required:true
        },
        EntryOrderData:{
            type:Object,
            required:true 
        },
        


    },
    methods: {
      scaleChange(){
          this.EntryOrderData.RealMoney = this.EntryOrderData.Scale * this.EntryOrderData.SumMoney / 100.0
      },
      testChange(val){
        this.$emit('testChange',val);
       },
      cancel(){
           this.loading = false; 
          let data = {
            mode:false
          }
          this.$emit('cancelCallBack', data);
       },
      //提交编辑后的userInfo
      handleSubmit(name,status) {
        
        this.$refs[name].validate(valid => { 
          console.log("提交验证：",valid)    
          if (valid) {  
            this.loading = true;      
            this.submit(status);
          } else {
            this.$Message.error("请填写相关信息!");
          }
        });
      },
    submit(status){
      var accountPerson = getToken() 
      var accountTime = timestampToDate(new Date(),'yyyy-MM-dd HH:mm:ss')
        const data = {
            Id:this.EntryOrderData.Id,
            OrderNo: this.EntryOrderData.OrderNo,
            ApplyTime: this.EntryOrderData.ApplyTime,
            CustomerName: this.EntryOrderData.CustomerName,
            LinkTelephone: this.EntryOrderData.LinkTelephone,
            BankName:this.EntryOrderData.BankName,
            BankAccount:this.EntryOrderData.BankAccount,
            Carrier:this.EntryOrderData.Carrier,
            CarrierTelephone:this.EntryOrderData.CarrierTelephone,
            VehicleNo:this.EntryOrderData.VehicleNo,
            RoughWeightPerson:this.EntryOrderData.RoughWeightPerson,
            RoughWeightTime:this.EntryOrderData.RoughWeightTime,
            RoughWeight:this.EntryOrderData.RoughWeight,
            SkinWeightPerson:this.EntryOrderData.SkinWeightPerson,
            SkinWeightTime:this.EntryOrderData.SkinWeightTime,
            SkinWeight:this.EntryOrderData.SkinWeight,
            NetWeight:this.EntryOrderData.NetWeight,
            CheckPerson:this.EntryOrderData.CheckPerson,
            CheckTime:this.EntryOrderData.CheckTime,

            //品种1信息
            CheckTypeFstId:this.EntryOrderData.CheckTypeFstId,
            CheckTypeFst:this.EntryOrderData.CheckTypeFst,
            CheckFstCount:this.EntryOrderData.CheckFstCount,
            CheckFstPrice:this.EntryOrderData.CheckFstPrice,
            CheckFstDlvCount:this.EntryOrderData.CheckFstDlvCount,
            CheckFstRemCount:this.EntryOrderData.CheckFstCount,

            //品种2信息
            CheckTypeSecId:this.EntryOrderData.CheckTypeSecId,
            CheckTypeSec:this.EntryOrderData.CheckTypeSec,
            CheckSecCount:this.EntryOrderData.CheckSecCount,
            CheckSecPrice:this.EntryOrderData.CheckSecPrice,
            CheckSecDlvCount:this.EntryOrderData.CheckSecDlvCount,
            CheckSecRemCount:this.EntryOrderData.CheckSecCount,

            //品种3信息
            CheckTypeThdId:this.EntryOrderData.CheckTypeThdId,
            CheckTypeThd:this.EntryOrderData.CheckTypeThd,
            CheckThdCount:this.EntryOrderData.CheckThdCount,
            CheckThdPrice:this.EntryOrderData.CheckThdPrice,
            CheckThdDlvCount:this.EntryOrderData.CheckThdDlvCount,
            CheckThdRemCount:this.EntryOrderData.CheckThdCount,

            //装箱类型
            CheckPackId:this.EntryOrderData.CheckPackId,
            CheckPack: this.EntryOrderData.CheckPack,
            UnitWeight:this.EntryOrderData.UnitWeight,

             //检验信息
            SugarRate:this.EntryOrderData.SugarRate,
            ImpurityRate:this.EntryOrderData.ImpurityRate,
            WaterRate:this.EntryOrderData.WaterRate,
            InsectRate:this.EntryOrderData.InsectRate,

            //入库人员及时间
            StorePerson:this.EntryOrderData.StorePerson,
            StoreTime:this.EntryOrderData.StoreTime,

            //品种1入库信息
            LandingPlaceFstId:this.EntryOrderData.LandingPlaceFstId,
            LandingPlaceFst:this.EntryOrderData.LandingPlaceFst,

            //品种2入库信息
            LandingPlaceSecId:this.EntryOrderData.LandingPlaceSecId,
            LandingPlaceSec:this.EntryOrderData.LandingPlaceSec,

            //品种3入库信息
            LandingPlaceThdId:this.EntryOrderData.LandingPlaceThdId,
            LandingPlaceThd:this.EntryOrderData.LandingPlaceThd,

            //结算信息
            AccountPerson:accountPerson,
            AccountTime:accountTime,
            AccountWeight:this.EntryOrderData.AccountWeight,
            SumMoney:this.EntryOrderData.SumMoney,
            RealMoney:this.EntryOrderData.RealMoney,
            Scale:this.EntryOrderData.Scale,
            Status:status

    };
      updateEntryOrderData(data).then(res =>{
            if(res == "OK"){
              this.$Message.success("提交成功");
              this.loading = false; 
              let data = {
                mode:false
              }
              this.$emit('success', data);   
            }else if(response.data.flag == 0){
            this.$Message.success("提交失败"); 
            }else if(response.data.flag == 2){
            this.$Message.success("状态过期");
            }
        }).catch(error => {
            this.$Message.error("请核对之后重新提交1");
             this.loading = false; 
       });


     },
    },
    mounted () {
      const cmpdata = {
        fields:"Id,CompanyName",
        offset:"0",
        limit:"-1"
      };
      const dptdata = {
        fields:"Id,DeptName",
        offset:"0",
        limit:"-1"
      };

      //计算重量及金额
      var unitWeight = this.EntryOrderData.UnitWeight        //单件重量
      var checkFstCount = this.EntryOrderData.CheckFstCount  //品1数量
      var checkFstPrice = this.EntryOrderData.CheckFstPrice  //品1单价
      var checkSecCount = this.EntryOrderData.CheckSecCount  //品2数量
      var checkSecPrice = this.EntryOrderData.CheckSecPrice  //品2单价
      var checkThdCount = this.EntryOrderData.CheckThdCount  //品3数量
      var checkThdPrice = this.EntryOrderData.CheckThdPrice  //品3单价

      var scale = this.EntryOrderData.Scale

      var accountWeight = unitWeight * (checkFstCount + checkSecCount + checkThdCount)
      
      var sumMoney = unitWeight * (checkFstCount * checkFstPrice + checkFstCount * checkFstPrice + checkFstCount * checkFstPrice)
      
      var realMoney = scale * sumMoney

      console.log("结算金额：",sumMoney)
      this.EntryOrderData.SumMoney = sumMoney
      this.EntryOrderData.AccountWeight = accountWeight
      this.EntryOrderData.RealMoney = realMoney
      //获得包含公司Id和companyname字段的全部列表
      // getCompanyList(cmpdata).then(res =>{
      //   this.CompanyList = res.List;
        
      // });
      //获得包含公司Id和companyname字段的全部列表
      // getDeptList(dptdata).then(res =>{
      //   this.DeptList = res.List;
      // });
    },
    watch: {
        edit(val) {
        this.mode = val
    }
}
}
</script>
<style>
.dept .ivu-select-placeholder{
color:#515a6e!important;
}

.orders_disabled_custom input{
    border:none;
    background-color:#fff!important;
    color:gray!important;
    width: 280px;
}

.buttn_rough{
  width: 100px;
}

.buttn_skin{
  width: 100px;
  margin-left: 150px;
}
</style>